package exception;

import java.util.InputMismatchException;
import java.util.Scanner;

public class Demo {
    public static void main(String[] args) throws Exception{
//        int[] s = null;
//        System.out.println(s.length);

//        int[] array = {1,2,3,4,5};
//        System.out.println(array[10]);

//        System.out.println(10 / 0);

//        int[] array = {1,2,3};
//        System.out.println(getKey(array, 3));

        int a = getValue();
        System.out.println(a);
    }
    // 一个读取数组 array 中下标为 index 值的方法
    public static int getKey(int[] array,int index){
        if(array == null){
            throw new NullPointerException("数组为空");
        }
        if(index < 0 || index > array.length - 1){
            throw new ArrayIndexOutOfBoundsException("下标越界");
        }
        return array[index];
    }
    public static int getValue(){
        Scanner scanner = null;
        try{
            scanner = new Scanner(System.in);
            int a = scanner.nextInt();
            return a;
        }catch (InputMismatchException e){
            e.printStackTrace();
        }finally {
            System.out.println("finally中的代码...");
        }
        System.out.println("try-catch-finally后的代码...");
        if(scanner != null){
            scanner.close();
        }
        return 0;
    }
}
